package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.dao.GsQueryMapper;
import net.anzhuo.entity.GsQuery;
import net.anzhuo.service.GsQueryService;

@Service
public class GsQueryServiceImpl implements GsQueryService {

	@Autowired
	private GsQueryMapper gsQueryMapper;
	
	@Override
	public GsQuery getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsQueryMapper.getById(id);
	}

	@Override
	public List<GsQuery> getBycoMd5(GsQuery coMd5) {
		// TODO Auto-generated method stub
		return gsQueryMapper.getByCoMd5(coMd5);
	}

	@Override
	public PaginationVO<GsQuery> getListWithPage(GsQuery gsCheck) {
		PaginationVO<GsQuery> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsQueryMapper.getListWithPage(gsCheck));
		paginationVO.setTotalCount(gsQueryMapper.getCount(gsCheck.getKeyNo()));
		paginationVO.setTotalPage((gsQueryMapper.getCount(gsCheck.getKeyNo()) + gsCheck.getPageSize() -1)  / gsCheck.getPageSize());
		paginationVO.setPageNo(gsCheck.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsQuery> getList() {
		// TODO Auto-generated method stub
		return  gsQueryMapper.getList();
	}

	@Override
	public List<GsQuery> getList(GsQuery gsCheck) {
		// TODO Auto-generated method stub
		return gsQueryMapper.getListByQuery(gsCheck);
	}
	
	@Override
	public List<GsQuery> getByKeyNo(GsQuery gsCheck) {
		// TODO Auto-generated method stub
		return gsQueryMapper.getByKeyNo(gsCheck);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsQuery gsCheck) {
		// TODO Auto-generated method stub
		gsQueryMapper.update(gsCheck);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsQuery gsCheck) {
		// TODO Auto-generated method stub
		gsQueryMapper.save(gsCheck);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		gsQueryMapper.delete(id);

	}

	@Override
	public int getCount(GsQuery gsPriority) {
		// TODO Auto-generated method stub
		return gsQueryMapper.getCount(gsPriority.getKeyNo());
	}

}
